<?php
header("content-type:text/html;charset=utf-8");
session_start();
//定义管理员用户
define("USERNAME","admin");
define("PASSWORD","123");
if($_POST['Submit']){
    $name=$_POST['username'];//用户名
    $psw=$_POST['password'];//密码

    if(($name==USERNAME&&$psw==PASSWORD)||
    (isset($_SESSION['user'][$name])&&isset($_SESSION['user'][$psw]))){
//        $_SESSION['user_id']=$name;
//        $_SESSION['count']=0;
        ini_set('date.timezone','Asia/Shanghai');//设置时区为亚洲/上海
        setcookie("user[xm]",$name,time()+3600);//传递用户名
        setcookie("user[dt]",date("Y-m-d H:i:s"),time()+3600);//登录时间
        setcookie("user[num]",0,time()+3600);//登录次数
        echo '<script language="JavaScript">
                  alert("登录成功,正在跳转...");
                window.location.href="./index.php";
            </script>';
    }else{
        echo '<script language="JavaScript">
            alert("用户名或密码不正确");
            window.location.href="./login.php";
        </script>';
    }
}
//    if(($name==USERNAME&&$psw==PASSWORD)||
//        (($name==$_SESSION['user_name']&&$psw==$_SESSION['user_psw']))){
//
//        $_SESSION['user_id']=$name;
//        ?>
<!--        <script language="JavaScript">-->
<!--            alert("登录成功,正在跳转...");-->
<!--            window.location.href="./index.php";-->
<!--        </script>-->
<!--    --><?php
//    }else{
//        ?>
<!--        <script language="JavaScript">-->
<!--            alert("用户名或密码不正确");-->
<!--            window.location.href="./login.php";-->
<!--        </script>-->
<!--    --><?php
//    }
//}

?>